#pragma once
#include <cstdio>
#include <string>
#include <mutex> // Required for thread-safe logging

// Define a thread-safe file logger
#ifdef DEBUG_MODE
    // Create a static mutex to protect file access
    static std::mutex log_mutex;

    // The new LOG_DEBUG macro that writes to a file
    #define LOG_DEBUG(format, ...) \
        do { \
            /* Lock the mutex to ensure only one thread can write at a time */ \
            std::lock_guard<std::mutex> lock(log_mutex); \
            /* Open the log file in append mode */ \
            FILE* log_file = fopen("debug.log", "a"); \
            if (log_file) { \
                /* Write the formatted log message */ \
                fprintf(log_file, "[DEBUG] " format "\n", ##__VA_ARGS__); \
                /* Close the file */ \
                fclose(log_file); \
            } \
        } while (false)
#else
    // In release mode, the macro is empty and does nothing
    #define LOG_DEBUG(format, ...)
#endif
